/**
 * Date:2021年3月15日 上午10:49:09
 * Copyright (c) 2021, www.bwbroad.com All Rights Reserved
 */

package com.app.rabbit;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import com.rabbitmq.client.Channel;

/**
 * Description: Rabbit消息消费端 <br/>
 * Date:2021年3月15日 上午10:49:09 <br/>
 * 
 * @author xuejianxin
 */
@Component
@EnableRabbit
public class TopicConsumer {

	private static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(TopicConsumer.class);

	@RabbitListener(queues = "topicQueue1")
	@RabbitHandler
	public void topic1Handler(Message message, Channel channel) throws Exception {
		// DeliveryTag代表的是这个消息在队列中的序号，这个信息存放在MessageProperties中
		channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
		log.info("topic1Handler ,RoutingKey={} msg={}", message.getMessageProperties().getReceivedRoutingKey(),
				new String(message.getBody()));
	}

	// 第二个消费者
	@RabbitListener(queues = "topicQueue2")
	@RabbitHandler
	public void topic2Handler(Message message, Channel channel) throws Exception {
		// DeliveryTag代表的是这个消息在队列中的序号，这个信息存放在MessageProperties中
		channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
		log.info("topic2Handler ,RoutingKey={} msg={}", message.getMessageProperties().getReceivedRoutingKey(),
				new String(message.getBody()));
	}

}
